<%inherit file="base.html"/>
<%def name="head()">
<script>

function do_pause(account_number)
{
    if (!confirm("确认操作吗？")) {
        return;
    }
    params = {account_number:account_number};
    $.post("/bus/account/pause", params, function (data) {
        alert(data.msg)
        window.location.reload();
    },"json");
}

function do_resume(account_number)
{
    if (!confirm("确认操作吗？")) {
        return;
    }
    params = {account_number:account_number};
    $.post("/bus/account/resume", params, function (data) {
        alert(data.msg)
        window.location.reload();
    },"json");
}    

function release(account_number)
{
    params = {account_number:account_number};
    $.post("/ops/user/release", params, function (data) {
        alert(data.msg)
        location.href.reload();
    },"json");
}

function do_delete(account_number)
{
    if(confirm("删除账号将删除账号所有相关数据，包括账号，日志，订单等，不可恢复，确认操作吗？")) {
        window.location.href = "/bus/account/delete?account_number="+account_number;
    }
    
}

</script>
</%def>
<%def name="body()">
    <div class="panel panel-default">
    <div class="panel-heading"><span class="glyphicon glyphicon-th"></span> 用户信息 <a class="badge pull-right" href="javascript:history.go(-1);">返回</a></div>
        <div class="panel-body">
        <div class="pull-right bottom10 ">
            % if permit.match('/bus/account/open'):
            <a href="/bus/account/open?member_id=${member.member_id}" class="btn btn-sm btn-info">新开认证账号</a>
            % endif
             % if permit.match('/bus/member/update'):
            <a href="/bus/member/update?member_id=${member.member_id}" class="btn btn-sm btn-info">修改基本资料</a>
             % endif
        </div>    
        <table class="table ">
                <thead>
                    <tr>
                        <th colspan="6"> 基本信息</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>用户姓名</td>
                        <td>${member.realname}</td>
                        <td>证件号码</td>
                        <td>${member.idcard}</td>
                        <td>用户登陆名</td>
                        <td>${member.member_name}</td>                 
                    </tr>
                    <tr>
                        <td>年龄</td>
                        <td>${member.age}</td>
                        <td>email</td>
                        <td>${member.email}
                        % if member.email:
                        (${member.email_active == 1 and u'已绑定' or u'未绑定'})
                        % endif
                        </td>
                        <td>联系电话</td>
                        <td>${member.mobile}</td>
                    </tr>      
                    <tr>
                        <td>地址</td>
                        <td>${member.address}</td>
                        <td>创建时间</td>
                        <td>${member.create_time}</td>
                        <td>更新时间</td>
                        <td>${member.update_time}</td>                        
                    </tr>                                                                       
            </tbody>
        </table>

        <table class="table ">
            <thead>
                <tr>
                    <th colspan="8"> 上网账号列表</th>
                </tr>
            </thead>
            <tbody>
            <tr class="active">
                <th>账号</th>
                <th>资费</th>
                <th>状态</th>
                <th>到期</th>
                <th>余额</th>
                <th>时长</th>
                <th>流量</th>
                <!-- <th>最近停机</th> -->
                <th></th>
            </tr>            
            % for user in accounts:
            <tr>
                <td><a href="/ops/user/detail?account_number=${user.account_number}">${user.account_number}</a></td>
                <td>${user.product_name}</td>
                <td>${{1:u"正常",2:u"停机",3:u"销户",4:u"到期",6:u"未激活"}[user.status]}</td>
                <td>${user.expire_date}</td>
                <td>${fen2yuan(user.balance)} 元</td>
                <td>${sec2hour(user.time_length)}小时</td>
                <td>${kb2mb(user.flow_length)}M</td>
                <!-- <td>${(user.last_pause or '')[:10]}</td> -->
                 <td>
                 <a class="opt-btn btn-default" href="/bus/account/update?account_number=${user.account_number}">修改</a>
                    % if user.status == 2:
                    
                        % if permit.match('/bus/account/resume'):
                        <a class="opt-btn btn-default" href="javascript:do_resume('${user.account_number}');">复机</a>
                        % endif
                        
                    % elif user.status == 1:
                    
                        % if permit.match('/bus/account/pause'):
                        <a class="opt-btn btn-default" href="javascript:do_pause('${user.account_number}');">停机</a>
                        % endif
                        
                        % if user.product_policy in (0,2,3,5):
                        
                            % if permit.match('/bus/account/next'):
                            <a class="opt-btn btn-default" href="/bus/account/next?account_number=${user.account_number}">续费</a>
                            % endif
                            
                        % elif user.product_policy in (1,4): 
                            
                            % if permit.match('/bus/account/charge'):
                            <a class="opt-btn btn-default" href="/bus/account/charge?account_number=${user.account_number}">充值</a>
                            % endif
                            
                        % endif
                        
                        % if permit.match('/bus/account/cancel'):   
                        <a class="opt-btn btn-default" href="/bus/account/cancel?account_number=${user.account_number}">销户</a>
                        % endif
                    
                        % if permit.match('/ops/user/release'):
                        <a class="opt-btn btn-default" href="javascript:release('${user.account_number}');">解绑</a>
                        % endif
                        
                    % elif user.status == 4:
                    
                        % if permit.match('/bus/account/next'):
                        <a class="opt-btn btn-default" href="/bus/account/next?account_number=${user.account_number}">续费</a>
                        % endif
                        
                    % endif
                    % if permit.match('/bus/account/delete'):
                    <a class="opt-btn btn-default" href="javascript:do_delete('${user.account_number}');">删除</a>
                    % endif
                 </td>
            </tr>
            % endfor
            </tbody>
        </table>  
        
        <table class="table ">
            <thead>
                <tr>
                    <th colspan="8"> 用户订购记录</th>
                </tr>
            </thead>
            <tbody>
            <tr class="active">
                <th>订单号</th>
                <th>资费</th>
                <th>用户账号</th>
                <th>订单费用</th>
                <th>实缴费用</th>
                <th>订单状态</th>
                <th>订单时间</th>
                <th>订单描述</th>
            </tr>            
            % for order in orders:
            <tr>
                <td>${order.order_id}</td>
                <td>${order.product_name}</td>
                <td>${order.account_number}</td>
                <td>${fen2yuan(order.order_fee)}</td>
                <td>${fen2yuan(order.actual_fee)}</td>
                <td>${{0:u"未支付",1:u"已支付",2:u"已取消"}[order.pay_status]}</td>
                <td>${order.create_time}</td>
                <td>${order.order_desc or ''}</td>
            </tr>
            % endfor
            </tbody>
        </table>    

    </div>
</div>
</div>
</%def>